package com.example.addemoone.kotlin

fun main() {
    val vehicle1 = Vehicle("轿车")
    vehicle1.intro()
    val vehicle2 = Vehicle("自行车", 3)
    vehicle2.intro()
}

class Vehicle(val type: String) {
    var wheels: Int = 0

    init {
        wheels = when(type) {
            "轿车" -> 4
            "自行车" -> 2
            "飞机" -> 6
            "大卡车" -> 8
            else -> 0
        }
    }

    constructor(type: String, wheels: Int) : this(type) {
        this.wheels = wheels
    }

    fun intro() {
        println("这是一辆 $type, 有 $wheels 个轮子")
    }
}
